#include<iostream>
#include<stdio.h>
using namespace std;
#include <iomanip>
#include  <cmath>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i, j;
    while (cin >> i >> j)
    {
        switch (j)
        {
        case 1:cout << 31 << endl;
            break;
        case 2:  if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
            cout << 29 << endl;
              else
            cout << 28 << endl;
            break;
        case 3:
            cout << 31 << endl;
            break;
        case 4:
            cout << 30 << endl;
            break;
        case 5:
            cout << 31 << endl;
            break;
        case 6:cout << 30 << endl;
            break;
        case 7:cout << 31 << endl;
            break;
        case 8:cout << 31 << endl;
            break;
        case 9:cout << 30 << endl;
            break;
        case 10:cout << 31 << endl;
            break;
        case 11:cout << 30 << endl;
            break;
        case 12:cout << 31 << endl;
            break;
        }

    }

}